fix(automation): region-aware run-history compaction keeps loop containers + early failures (#3234)#3240
Merged
Conversation
…iners + early failures (#3234) `compactStepsForHistory` bounded a terminal run's persisted step log to the last `MAX_PERSISTED_HISTORY_STEPS` entries with a plain tail-slice. With the ADR-0031 structured-region step logs (#1505) a single `loop` can emit `iterations × body-steps` entries, so the tail-slice dropped the `loop`/`parallel`/`try_catch` container step (it precedes all its body steps) and every early iteration — leaving `getRun`/`listRuns` (after a restart or ring-buffer eviction) with body steps the Runs surface could no longer nest, and silently hiding an early failure. Introduce an exported, region-aware `compactStepLogForHistory`; the private method now delegates to it. Over budget it keeps the run's structural backbone — every top-level step (including the region container steps) and every failure, each pulled in with its ancestor container chain — plus the most recent body steps, order-preserving and hard-capped at `max` so `steps_json` stays bounded (#2585). Every retained body step keeps its enclosing container(s), so the compacted log never contains an orphan and the observability surface's per-iteration / per-region nesting still reconstructs. Under budget behavior is unchanged (whole log, stacks stripped). Adds 7 unit tests (cap, container/backbone retention, recent-iteration tail, early-failure retention, order preservation, nested-container no-orphan). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VuvxWgoadqryqBcjs7TpVi
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 6 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
…g in flows.mdx The "Runs" section still described run history as an in-memory ring buffer whose `sys_automation_run` rows "hold only live pauses", so "history starts fresh on each boot". That predates the durable terminal run history (#2585): terminal runs (completed / failed) are mirrored to `sys_automation_run` with a bounded step log, and `listRuns` / `getRun` merge it so a run's status / steps / failure reason survive a restart or ring-buffer eviction. Also note the Studio Runs panel now nests body steps by iteration / branch / handler (#1505, objectui #2667). Surfaced by the docs-drift check on #3240. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VuvxWgoadqryqBcjs7TpVi
os-zhuang
marked this pull request as ready for review
July 18, 2026 20:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #1505 (region step logs).
AutomationEngine.compactStepsForHistory()bounded a terminal run's persisted step log to the lastMAX_PERSISTED_HISTORY_STEPSentries with a plain tail-slice. With the ADR-0031 structured-region step logs, a singleloopcan now emititerations × body-stepsentries, so the tail-slice:loop/parallel/try_catchcontainer step (it precedes all its body steps), leavinggetRun/listRuns— served from durable history after a restart or ring-buffer eviction — with body steps the Runs surface (objectuiFlowRunsPanel) could no longer nest; andThe fix
New exported, region-aware
compactStepLogForHistory(the private method delegates to it). Under budget the log is kept whole (stacks stripped) — unchanged. Over budget it selects a bounded, order-preserving subset that keeps the run's structural backbone:parentNodeId === undefined) —start/end, main-graph nodes, and the region container steps (bounded by the flow's static node count, not by loop iterations);Every retained body step therefore keeps its enclosing container(s) — so the compacted log never contains an orphan and the observability surface's per-iteration / per-region nesting still reconstructs — and the result is hard-capped at
max, sosteps_jsonstays bounded (#2585). Parent lookup is O(n) via a running last-seen-index map (the same "nearest preceding container instance" thatFlowRunsPanel.buildStepTreenests under).Verification
run-history.test.ts— 14/14 pass (7 new: cap, container/backbone retention, recent-iteration tail, early-failure retention, order preservation, nested-container no-orphan).@objectstack/service-automationsuite — 326/326 pass (no regression).tsupbuild incl. DTS typecheck — pass. ESLint — clean.@objectstack/service-automationminor.Closes #3234.
🤖 Generated with Claude Code
Generated by Claude Code